package dao.impl;

import dao.FoodDao;
import model.Food;
import utils.DbUtil;

import java.util.List;

/**
 * @author cyc20
 */
public class FoodDaoImpl implements FoodDao {

    @Override
    public List<Food> listFoodbyBusinessId(Integer businessId) {
        return DbUtil.select(Food.class,"business_id=?",businessId);
    }

    @Override
    public int saveFood(Food food) {
        return DbUtil.insertSelective(food);
    }

    @Override
    public Food getFoodById(Integer foodId) {
        List<Food>list=DbUtil.select(Food.class,"food_id=?",foodId);
        if (list!=null&&list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public int updateFood(Food food) {
        Integer foodId=food.getFoodId();
        food.setFoodId(null);
        return DbUtil.update(food,"food_id=?",foodId);
    }

    @Override
    public int removeFood(Integer foodId) {

        return DbUtil.delete(Food.class,"food_id=?",foodId);
    }

    @Override
    public List<Food> listFoodByBusinessId(Integer businessId) {
        return DbUtil.select(Food.class,"business_id=?",businessId);
    }
}
